<template>
  <div id="wkEmployee">
    <Breadcrumb content="员工档案管理" />
    <div class="bodyContent">
      <Splitpanes class="area">
        <Pane size="20">
          <vxe-toolbar perfect>
            <template #buttons>
              <vxe-button
                type="text"
                icon="vxe-icon-refresh"
                class="button-blue"
                content="刷新"
                :loading="showLoading"
                @click="findWkEmplyeeList"
              ></vxe-button>
              <vxe-button
                type="text"
                icon="vxe-icon-delete"
                class="button-red"
                content="删除"
                @click="handleDelete"
              ></vxe-button>
            </template>
          </vxe-toolbar>
          <div class="wkEmployeeBox">
            <vxe-table
              ref="wkEmployeeTableRef"
              :loading="showLoading"
              class="mytable-scrollbar"
              border
              align="left"
              height="auto"
              :keep-source="true"
              :data="wkEmployeeList"
              :row-config="{ isCurrent: true, isHover: true }"
              @current-change="currentChangeEvent"
              resizable
              show-overflow
            >
              <vxe-column type="checkbox" align="center" width="26"></vxe-column>
              <vxe-column type="seq" title="序号" align="center" width="30"></vxe-column>
              <vxe-column field="code" title="工号"></vxe-column>
              <vxe-column field="name" title="姓名"></vxe-column>
              <vxe-column field="sex" title="性别" :formatter="formatterSex"></vxe-column>
              <vxe-column field="age" title="年龄"></vxe-column>
            </vxe-table>
          </div>
        </Pane>
        <Pane size="80">
          <el-tabs type="border-card">
            <el-tab-pane label="首页">
              <WkEmployeeHome></WkEmployeeHome>
            </el-tab-pane>
            <el-tab-pane label="基本信息"
              ><el-form
                ref="wkEmployeeFormRef"
                :model="wkEmployeeForm"
                :rules="baseFormRules"
                label-width="100px"
                class="form-input-m baseForm"
                v-loading="showLoading"
                inline-message
              >
                <el-scrollbar style="height: 100%">
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="工号" prop="code">
                        <el-input
                          v-model="wkEmployeeForm.code"
                          placeholder="工号"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="姓名" prop="name">
                        <el-input
                          v-model="wkEmployeeForm.name"
                          placeholder="姓名"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="性别" prop="sex">
                        <el-select
                          v-model="wkEmployeeForm.sex"
                          style="width: 200px"
                          placeholder="性别"
                        >
                          <el-option
                            v-for="item in sexOptions"
                            :key="item.value"
                            :label="item.name"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="年龄" prop="age">
                        <el-input
                          v-model="wkEmployeeForm.age"
                          placeholder="年龄"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="血型" prop="bloodType">
                        <el-select
                          v-model="wkEmployeeForm.bloodType"
                          style="width: 200px"
                          placeholder="血型"
                        >
                          <el-option
                            v-for="item in bloodDicts"
                            :key="item.commonId"
                            :label="item.bloodName"
                            :value="item.bloodCode"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="出生日期" prop="birthday">
                        <el-date-picker
                          v-model="wkEmployeeForm.birthday"
                          type="date"
                          placeholder="出生日期"
                          clearable
                        />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="组织机构" prop="orgId">
                        <el-select
                          v-model="wkEmployeeForm.orgId"
                          placeholder="请选择"
                          ref="selectOrgRef"
                          filterable
                          style="width: 200px"
                        >
                          <el-option
                            hidden
                            :value="wkEmployeeForm.orgId ? wkEmployeeForm.orgId : ''"
                            :label="wkEmployeeForm.orgName"
                          ></el-option>
                          <el-tree
                            filterable
                            :data="orgList"
                            :props="defaultProps"
                            :expand-on-click-node="false"
                            :default-expand-all="true"
                            @node-click="handleOrgNodeClick"
                            highlight-current
                            ref="orgTreeRef"
                            node-key="id"
                            class="tools-tree"
                          ></el-tree>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="科室" prop="deptId">
                        <!-- @clear="handleDeptClear" -->
                        <el-select
                          v-model="wkEmployeeForm.deptId"
                          placeholder="请选择"
                          
                          ref="selectDeptRef"
                          clearable
                          style="width: 200px"
                          filterable
                        >
                          <el-option
                            hidden
                            :value="wkEmployeeForm.deptId ? wkEmployeeForm.deptId : ''"
                            :label="wkEmployeeForm.deptName"
                          ></el-option>
                          <el-tree
                            filterable
                            :data="deptList"
                            :props="defaultProps"
                            :expand-on-click-node="false"
                            :default-expand-all="true"
                            @node-click="handleDeptNodeClick"
                            highlight-current
                            ref="deptTreeRef"
                            node-key="id"
                            class="tools-tree"
                          ></el-tree>
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="岗位" prop="position">
                        <el-select
                          v-model="wkEmployeeForm.position"
                          style="width: 200px"
                          placeholder="岗位"
                        >
                          <el-option
                            v-for="item in positionDicts"
                            :key="item.commonId"
                            :label="item.position"
                            :value="item.code"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="职务" prop="post">
                        <el-input
                          v-model="wkEmployeeForm.post"
                          placeholder="职务"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="职称" prop="professional">
                        <el-select
                          v-model="wkEmployeeForm.professional"
                          style="width: 200px"
                          placeholder="职称"
                        >
                          <el-option
                            v-for="item in professionalDicts"
                            :key="item.commonId"
                            :label="item.professional"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="用工形式" prop="employForm">
                        <el-input
                          v-model="wkEmployeeForm.employForm"
                          placeholder="用工形式"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="入职日期" prop="joinSysDate">
                        <el-date-picker
                          v-model="wkEmployeeForm.joinSysDate"
                          type="date"
                          placeholder="入职日期"
                          clearable
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="参加工作日期" prop="joinWorkDate">
                        <el-date-picker
                          v-model="wkEmployeeForm.joinWorkDate"
                          type="date"
                          placeholder="参加工作日期"
                          clearable
                        /> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="办公电话" prop="officePhone">
                        <el-input
                          v-model="wkEmployeeForm.officePhone"
                          placeholder="办公电话"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="状态" prop="status">
                        <el-select v-model="wkEmployeeForm.status" class="m-2" placeholder="状态" style="width: 200px">
                          <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="默认学历" prop="defaultEducation">
                        <el-select
                          v-model="wkEmployeeForm.defaultEducation"
                          style="width: 200px"
                          placeholder="默认学历"
                        >
                          <el-option
                            v-for="item in educationDicts"
                            :key="item.commonId"
                            :label="item.education"
                            :value="item.code"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="默认专业" prop="defaultSpecialties">
                        <el-select
                          v-model="wkEmployeeForm.defaultSpecialties"
                          style="width: 200px"
                          placeholder="默认专业"
                        >
                          <el-option
                            v-for="item in specialtiesDicts"
                            :key="item.commonId"
                            :label="item.specialtieName"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="默认专业方向" prop="defaultProDirection">
                        <el-select
                          v-model="wkEmployeeForm.defaultProDirection"
                          style="width: 200px"
                          placeholder="默认专业方向"
                        >
                          <el-option
                            v-for="item in proDirectionDicts"
                            :key="item.commonId"
                            :label="item.proDirection"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="第一外语" prop="froeignLang">
                        <el-input
                          v-model="wkEmployeeForm.froeignLang"
                          placeholder="第一外语"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="第一外语级别" prop="frolanLevel">
                        <el-input
                          v-model="wkEmployeeForm.frolanLevel"
                          placeholder="第一外语级别"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="档案号" prop="fileCode">
                        <el-input
                          v-model="wkEmployeeForm.fileCode"
                          placeholder="档案号"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="档案所在地" prop="fileAddress">
                        <el-input
                          v-model="wkEmployeeForm.fileAddress"
                          placeholder="档案所在地"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="社会保障号" prop="ssNum">
                        <el-input
                          v-model="wkEmployeeForm.ssNum"
                          placeholder="社会保障号"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="曾用名" prop="usedName">
                        <el-input
                          v-model="wkEmployeeForm.usedName"
                          placeholder="曾用名"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="身份证号" prop="idNo">
                        <el-input
                          v-model="wkEmployeeForm.idNo"
                          placeholder="身份证号"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="户口性质" prop="characterrpr">
                        <el-input
                          v-model="wkEmployeeForm.characterrpr"
                          placeholder="户口性质"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="籍贯" prop="nativeplace">
                        <el-input
                          v-model="wkEmployeeForm.nativeplace"
                          placeholder="籍贯"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="民族" prop="nationality">
                        <el-select
                          v-model="wkEmployeeForm.nationality"
                          style="width: 200px"
                          placeholder="民族"
                          filterable
                        >
                          <el-option
                            v-for="item in nationalityDicts"
                            :key="item.value"
                            :label="item.text"
                            :value="item.value"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="国家/地区" prop="country">
                        <el-input
                          v-model="wkEmployeeForm.country"
                          placeholder="国家/地区"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="省/自治区" prop="province">
                        <el-select
                          v-model="wkEmployeeForm.province"
                          style="width: 200px"
                          placeholder="省/自治区"
                          filterable
                        >
                          <el-option
                            v-for="item in provinceDicts"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="城市/地区" prop="city">
                        <el-select
                          v-model="wkEmployeeForm.city"
                          style="width: 200px"
                          placeholder="省/自治区"
                          filterable
                        >
                          <el-option
                            v-for="item in cityDicts"
                            :key="item.code"
                            :label="item.name"
                            :value="item.code"
                          /> </el-select></el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="家庭住址" prop="address">
                        <el-input
                          v-model="wkEmployeeForm.address"
                          placeholder="家庭住址"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="婚姻状况" prop="marital">
                        <el-select
                          v-model="wkEmployeeForm.marital"
                          style="width: 200px"
                          placeholder="婚姻状况"
                        >
                          <el-option
                            v-for="item in maritalDicts"
                            :key="item.commonId"
                            :label="item.marital"
                            :value="item.code"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="结离(婚)日期" prop="marriageDate">
                        <el-date-picker
                          v-model="wkEmployeeForm.marriageDate"
                          type="date"
                          placeholder="结离(婚)日期"
                          clearable
                        /> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="政治面貌" prop="polity">
                        <el-select
                          v-model="wkEmployeeForm.polity"
                          style="width: 200px"
                          placeholder="岗位"
                          filterable
                        >
                          <el-option
                            v-for="item in polityDicts"
                            :key="item.commonId"
                            :label="item.polityName"
                            :value="item.polityCode"
                          /> </el-select></el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="入党日期" prop="joinPolityDate">
                        <el-date-picker
                          v-model="wkEmployeeForm.joinPolityDate"
                          type="date"
                          placeholder="入党日期"
                          clearable
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="技能水平" prop="skillLevel">
                        <el-select
                          v-model="wkEmployeeForm.skillLevel"
                          style="width: 200px"
                          placeholder="技能水平"
                        >
                          <el-option
                            v-for="item in skillLevelDicts"
                            :key="item.commonId"
                            :label="item.skillLevel"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="健康状况" prop="health">
                        <el-select
                          v-model="wkEmployeeForm.health"
                          style="width: 200px"
                          placeholder="健康状况"
                          filterable
                        >
                          <el-option
                            v-for="item in healthDicts"
                            :key="item.commonId"
                            :label="item.health"
                            :value="item.code"
                          />
                        </el-select> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="兴趣爱好" prop="interest">
                        <el-input
                          v-model="wkEmployeeForm.interest"
                          placeholder="兴趣爱好"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="联系电话" prop="phone">
                        <el-input
                          v-model="wkEmployeeForm.phone"
                          placeholder="联系电话"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                    <el-col :span="7">
                      <el-form-item label="手机号" prop="mobile">
                        <el-input
                          v-model="wkEmployeeForm.mobile"
                          placeholder="手机号"
                          clearable
                        ></el-input> </el-form-item
                    ></el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="7">
                      <el-form-item label="电子邮箱" prop="email">
                        <el-input
                          v-model="wkEmployeeForm.email"
                          placeholder="电子邮箱"
                          clearable
                        ></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="是否停用" prop="isDeactivate">
                        <el-switch
                          v-model="wkEmployeeForm.isDeactivate"
                          inline-prompt
                          active-text="是"
                          inactive-text="否"
                        ></el-switch>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row :gutter="0">
                    <el-col :span="21">
                      <el-form-item label="简介" prop="remake">
                        <el-input
                          v-model="wkEmployeeForm.remake"
                          placeholder="简介"
                          clearable
                          type="textarea"
                          style="width: 90%"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-form-item class="form-footer">
                    <template #default>
                      <el-button type="primary" @click="add()">新建</el-button>
                      <el-button type="primary" v-loading="saveLoading" @click="save()"
                        >保存</el-button
                      >
                      <el-button type="default" @click="add()">重置</el-button>
                    </template>
                  </el-form-item>
                </el-scrollbar>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="职务">
              <WkEmployeePost ref="wkEmployeePostRef"></WkEmployeePost>
            </el-tab-pane>
            <el-tab-pane label="职称">
              <WkEmployeeProfessional ref="WkEmployeeProfessionalRef"></WkEmployeeProfessional>
            </el-tab-pane>
            <el-tab-pane label="学历">
              <WkEmployeeEducation ref="WkEmployeeEducationRef"></WkEmployeeEducation>
            </el-tab-pane>
            <el-tab-pane label="专业">
              <WkEmployeeSpecialty ref="WkEmployeeSpecialtyRef"></WkEmployeeSpecialty>
            </el-tab-pane>
            <el-tab-pane label="专业方向">
              <WkEmployeeProDirection ref="WkEmployeeProDirectionRef"></WkEmployeeProDirection>
            </el-tab-pane>
            <el-tab-pane label="合同">
              <WkEmployeeContract ref="WkEmployeeContractRef"></WkEmployeeContract>
            </el-tab-pane>
            <el-tab-pane label="教育经历">
              <WkEmployeeEducatExper ref="WkEmployeeEducatExperRef"></WkEmployeeEducatExper>
            </el-tab-pane>
            <el-tab-pane label="工作履历">
              <WkEmployeeJobHistory ref="WkEmployeeJobHistoryRef"></WkEmployeeJobHistory>
            </el-tab-pane> </el-tabs
        ></Pane>
      </Splitpanes>
    </div>
  </div>
</template>

<script setup lang="ts">
// 引入组件区 ==========
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
import { Splitpanes, Pane } from 'splitpanes';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示信息
import { getNationality, getProvince, getCity } from '../../../utils/common';
import WkEmployeeHome from './WkEmployeeHome.vue';
import WkEmployeePost from './WkEmployeePost.vue';
import WkEmployeeProfessional from './WkEmployeeProfessional.vue';
import WkEmployeeEducation from './WkEmployeeEducation.vue';
import WkEmployeeSpecialty from './WkEmployeeSpecialty.vue';
import WkEmployeeProDirection from './WkEmployeeProDirection.vue';
import WkEmployeeContract from './WkEmployeeContract.vue';
import WkEmployeeEducatExper from './WkEmployeeEducatExper.vue';
import WkEmployeeJobHistory from './WkEmployeeJobHistory.vue';
import { validatePhoneTwo, validateEMail, validateID } from '@/utils/common'; //手机号(固话)+邮箱+身份证号校验正则

let { proxy }: any = getCurrentInstance();
let showLoading = ref(false);//左侧表格+右侧基本信息数据加载状态
const wkEmployeeList = reactive([]);
const wkEmployeeForm = reactive({
  id: '',
  code: '',
  name: '',
  orgId: '',
  orgName: '',
  deptId: '',
  deptName: '',
  sex: 0,
  age: '',
  bloodType: '',
  birthday: '',
  officePhone: '',
  polity: '',
  usedName: ''
});
// form表单校验规则
let baseFormRules: any = {
  officePhone: [
    {
      required: false,
      message: '请输入办公电话',
      trigger: 'blur'
    },
    {
      validator: validatePhoneTwo,
      trigger: 'blur'
    }
  ],
  phone: [
    {
      required: false,
      message: '请输入联系电话',
      trigger: 'blur'
    },
    {
      validator: validatePhoneTwo,
      trigger: 'blur'
    }
  ],
  mobile: [
    {
      required: false,
      message: '请输入手机号',
      trigger: 'blur'
    },
    {
      validator: validatePhoneTwo,
      trigger: 'blur'
    }
  ],
  email: [
    {
      required: false,
      message: '请输入邮箱',
      trigger: 'blur'
    },
    {
      validator: validateEMail,
      trigger: 'blur'
    }
  ],
  idNo: [
    {
      required: false,
      message: '请输入身份证号',
      trigger: 'blur'
    },
    {
      validator: validateID,
      trigger: 'blur'
    }
  ]
};
let saveLoading = ref(false); //保存
let sexOptions = reactive([]);
let statusOptions = reactive([
  {
    label: '在职',
    value: '0'
  },
  {
    label: '离职',
    value: '1'
  },
  {
    label: '解雇',
    value: '2'
  }
]);
const wkEmployeePostRef = ref(null);
const WkEmployeeProfessionalRef = ref(null);
const WkEmployeeEducationRef = ref(null);
const WkEmployeeSpecialtyRef = ref(null);
const WkEmployeeProDirectionRef = ref(null);
const WkEmployeeContractRef = ref(null);
const WkEmployeeEducatExperRef = ref(null);
const WkEmployeeJobHistoryRef = ref(null);
const dictTreeTypeCodes: any = reactive([
  'Sex',
  'ryda',
  'gwzd',
  'xxzd',
  'zczd',
  'xlzd',
  'zyzd',
  'mrzyfx',
  'hyzk',
  'jnsp',
  'jkzk',
  'mrzyfx',
  'hyzk',
  'jnsp',
  'jkzk'
]);

const bloodDicts = reactive([]);
const polityDicts = reactive([]);
const positionDicts = reactive([]);
const professionalDicts = reactive([]);
const educationDicts = reactive([]);
const specialtiesDicts = reactive([]);
const proDirectionDicts = reactive([]);
const maritalDicts = reactive([]);
const skillLevelDicts = reactive([]);
const healthDicts = reactive([]);

let orgList: any = reactive([]); //所有的组织机构
let deptList: any = reactive([]); //所有的部门
let defaultProps = {
  children: 'children',
  label: 'name'
};
let nationalityDicts = getNationality();
let provinceDicts = getProvince();
let cityDicts = getCity();
// 方法定义区 =============================================================
onMounted(() => {
  findWkEmplyeeList();
  getDictItemsList();
  findOrgTree();
});

// 批量获取字典
async function getDictItemsList() {
  const codes = dictTreeTypeCodes.join(',');
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: codes } });
  const sexs = dictTreeTypeItems.data.find((item) => item.code === 'Sex');
  sexOptions.push(...sexs.detailDataList);
  const itemClassType = dictTreeTypeItems.data.find((item) => item.code === 'ryda');
  polityDicts.push(...itemClassType.detailDataList);
  const instrClassType = dictTreeTypeItems.data.find((item) => item.code === 'gwzd');
  positionDicts.push(...instrClassType.detailDataList);
  const bloodTypes = dictTreeTypeItems.data.find((item) => item.code === 'xxzd');
  bloodDicts.push(...bloodTypes.detailDataList);
  const professionals = dictTreeTypeItems.data.find((item) => item.code === 'zczd');
  professionalDicts.push(...professionals.detailDataList);
  const educations = dictTreeTypeItems.data.find((item) => item.code === 'xlzd');
  educationDicts.push(...educations.detailDataList);
  const specialties = dictTreeTypeItems.data.find((item) => item.code === 'zyzd');
  specialtiesDicts.push(...specialties.detailDataList);
  const proDirections = dictTreeTypeItems.data.find((item) => item.code === 'mrzyfx');
  proDirectionDicts.push(...proDirections.detailDataList);
  const maritals = dictTreeTypeItems.data.find((item) => item.code === 'hyzk');
  maritalDicts.push(...maritals.detailDataList);
  const skillLevels = dictTreeTypeItems.data.find((item) => item.code === 'jnsp');
  skillLevelDicts.push(...skillLevels.detailDataList);
  const healths = dictTreeTypeItems.data.find((item) => item.code === 'jkzk');
  healthDicts.push(...healths.detailDataList);
}

function formatterSex({ cellValue }) {
  const item = sexOptions.find((item) => item.value === cellValue);
  return item ? item.label : '';
}

function findOrgTree() {
  orgList.length = 0;
  const url = '/api/sys/findOrgTree';
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        proxy.$alert(res.status.msg, '提示');
      } else {
        orgList.push(...res.data.orgTree);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取机构失败', VxeNotifyType.error);
    });
}

function handleOrgNodeClick(data: any) {
  wkEmployeeForm.orgId = data.id;
  wkEmployeeForm.orgName = data.name;
  wkEmployeeForm.deptId = '';
  wkEmployeeForm.deptName = '';
  findDeptTree();
  const selectOrgRef: any = proxy.$refs['selectOrgRef'];
  selectOrgRef.blur();
}

function handleDeptNodeClick(data: any) {
  wkEmployeeForm.deptId = data.id;
  wkEmployeeForm.deptName = data.name;
  const selectDeptRef: any = proxy.$refs['selectDeptRef'];
  selectDeptRef.blur();
}

function findDeptTree() {
  deptList.length = 0;
  const url = '/api/sys/findDeptTree';
  const obj = { orgId: wkEmployeeForm.orgId, orgName: wkEmployeeForm.orgName };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('获取部门失败', VxeNotifyType.error);
      } else {
        deptList.push(...res.data.deptList);
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

// 获取列表信息
function findWkEmplyeeList() {
  showLoading.value = true;
  wkEmployeeList.length = 0;
  const url = '/wk/employee/getEmployeeList';
  proxy.$http
    .get(url)
    .then((res: any) => {
      wkEmployeeList.push(...res.data);
      currentChangeEvent({ row: wkEmployeeList[0] });
      const $xTable = proxy.$refs.wkEmployeeTableRef as any;
      if ($xTable) {
        $xTable.setCurrentRow(wkEmployeeList[0]);
      }
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      proxy.$alert(err, '提示');
    });
}
// 添加
function add() {
  Object.keys(wkEmployeeForm).forEach((key) => {
    switch (typeof wkEmployeeForm[key]) {
      case 'string':
        wkEmployeeForm[key] = '';
        break;
      case 'number':
        wkEmployeeForm[key] = 0;
        break;
    }
  });
  const el: any = proxy.$refs.wkEmployeeFormRef;
  el.resetFields(); //重置表单，将值重置为初始值，并移除校验结果
}

// 保存
function save() {
  let url = '';
  if (wkEmployeeForm.id == '' || wkEmployeeForm.id == null || wkEmployeeForm.id == undefined) {
    url = '/wk/employee/addEmployee';
  } else {
    url = '/wk/employee/updateEmployee';
  }
  const el: any = proxy.$refs.wkEmployeeFormRef;
  if (!el) return;
  el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    proxy.$http
      .post(url, wkEmployeeForm)
      .then((res: any) => {
        VxeMessage(res.status.msg, VxeNotifyType.success);
        findWkEmplyeeList();
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
    add(); //清空表单
  });
}

// 行点击事件
function currentChangeEvent(row: any) {
  proxy.$nextTick(() => {
    wkEmployeePostRef.value?.findEmployeePostList(row.row.id);
    WkEmployeeProfessionalRef.value?.findEmployeeProfessionalList(row.row.id);
    WkEmployeeEducationRef.value?.findEmployeeEducationList(row.row.id);
    WkEmployeeSpecialtyRef.value?.findEmployeeSpecialtyList(row.row.id);
    WkEmployeeProDirectionRef.value?.findEmployeeProDirectionList(row.row.id);
    WkEmployeeContractRef.value?.findEmployeeContractList(row.row.id);
    WkEmployeeEducatExperRef.value?.findEmployeeEducatExperList(row.row.id);
    WkEmployeeJobHistoryRef.value?.findEmployeeJobHistoryList(row.row.id);
  });
  Object.assign(wkEmployeeForm, row.row);
}
// 删除
function handleDelete() {
  const $xTable = proxy.$refs.wkEmployeeTableRef as any;
  const selectRows = $xTable.getCheckboxRecords();
  if (selectRows.length <= 0) {
    VxeMessage('请先选中要删除的项', VxeNotifyType.warning);
    return;
  }
  proxy
    .$confirm('确定删除此项？', '提示', {
      cancelButtonClass: 'cancel-button',
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
    .then((type) => {
      if (type === 'confirm') {
        selectRows.forEach((item, idx) => {
          const url = '/wk/employee/deleteEmployee';
          proxy.$http
            .post(url, item)
            .then((res: any) => {
              if (idx === selectRows.length - 1) {
                VxeMessage('删除成功', VxeNotifyType.success);
                findWkEmplyeeList();
              }
            })
            .catch((err) => {
              VxeMessage(err.response.data.status.msg, VxeNotifyType.error);
            });
        });
      }
    });
}
</script>

<style lang="scss" scoped>
#wkEmployee {
  height: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    .area {
      background-color: $base-white;
      // 附加按钮间距
      .button-blue,
      .button-red {
        margin: 5px 0 5px 5px;
      }
      .wkEmployeeBox {
        height: calc(100% - 40px);
      }
      .el-tabs {
        height: 100%;
      }
      :deep(.el-tabs__content) {
        height: calc(100% - 39px);
        padding: 0;
        .el-tab-pane {
          height: 100%;
        }
        .el-tab-pane {
          padding: 0;
          height: 100%;
        }
        #pane-1 {
          padding: 15px;
          height: calc(100% - 30px);
          .el-form {
            height: 100%;
          }
        }
      }
    }
  }
}
</style>
